﻿namespace Services.Implement;

public partial interface IBaseBLL<T> where T : class, new()
{

    #region 插入数据
    /// <summary>
    /// 单个新增(同步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    bool Insert(T entity);

    /// <summary>
    /// 单个新增(异步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> InsertAsync(T entity);

    /// <summary>
    /// 单个新增(同步)返回自增列
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    int InsertReturnIdentity(T entity);

    /// <summary>
    /// 单个新增(异步)返回自增列
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<int> InsertReturnIdentityAsync(T entity);
    /// <summary>
    /// 批量新增(同步)
    /// </summary>
    /// <param name="entitys"></param>
    /// <returns></returns>
    bool Insert(List<T> entitys);

    /// <summary>
    /// 批量新增(异步)
    /// </summary>
    /// <param name="entitys"></param>
    /// <returns></returns>
    Task<bool> InsertAsync(List<T> entitys);

    /// <summary>
    /// 批量新增(异步)1000条以上
    /// </summary>
    /// <param name="entitys"></param>
    /// <returns></returns>
    Task<bool> BulkInsertCopyAsync(List<T> entitys);
    #endregion

    #region 更新数据
    /// <summary>
    /// 单个修改(同步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    bool Update(T entity);

    /// <summary>
    /// 单个修改(异步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> UpdateAsync(T entity);

    /// <summary>
    /// 批量修改(同步)
    /// </summary>
    /// <param name="entitys"></param>
    /// <returns></returns>
    bool Update(List<T> entitys);

    /// <summary>
    /// 批量修改(异步)
    /// </summary>
    /// <param name="entitys"></param>
    /// <returns></returns>
    Task<bool> UpdateAsync(List<T> entitys);

    /// <summary>
    /// 批量修改(异步)1000条以上
    /// </summary>
    /// <param name="entitys"></param>
    /// <returns></returns>
    Task<bool> BulkUpdateCopyAsync(List<T> entitys);
    #endregion

    #region 删除
    /// <summary>
    /// 单个删除(同步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    bool Delete(T entity);

    /// <summary>
    /// 单个删除(异步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> DeleteAsync(T entity);

    /// <summary>
    /// 根据id单个删除(同步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    bool Delete(int id);

    /// <summary>
    /// 根据id单个删除(异步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> DeleteAsync(int id);

    /// <summary>
    /// 根据委托表达式单个删除(同步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    bool Delete(Expression<Func<T, bool>> expression);

    /// <summary>
    /// 根据委托表达式单个删除(异步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> DeleteAsync(Expression<Func<T, bool>> expression);

    /// <summary>
    /// 批量删除(同步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    bool Delete(List<T> entitys);

    /// <summary>
    /// 批量删除(异步)
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<bool> DeleteAsync(List<T> entitys);
    #endregion

    #region 查询
    /// <summary>
    /// 获取数量(同步)
    /// </summary>
    /// <param name="expression">expression</param>
    /// <returns>返回值</returns>
    int GetCount(Expression<Func<T, bool>> expression);

    /// <summary>
    /// 获取数量(异步)
    /// </summary>
    /// <param name="expression">expression</param>
    /// <returns>返回值</returns>
    Task<int> GetCountAsync(Expression<Func<T, bool>> expression);

    /// <summary>
    /// 通过主键查询(同步)
    /// </summary>
    /// <param name="objId"></param>
    /// <returns></returns>
    T Get(object objId);

    /// <summary>
    /// 通过主键查询(异步)
    /// </summary>
    /// <param name="objId"></param>
    /// <returns></returns>
    Task<T> GetAsync(object objId);

    /// <summary>
    /// 根据条件查询单个实体(同步)
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    T Get(Expression<Func<T, bool>> whereExpression);

    /// <summary>
    /// 根据条件查询单个实体(异步)
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    Task<T> GetAsync(Expression<Func<T, bool>> whereExpression);

    /// <summary>
    /// 根据条件查询集合(同步)
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    List<T> GetList(Expression<Func<T, bool>>? whereExpression = null);

    /// <summary>
    /// 根据条件查询集合(异步)
    /// </summary>
    /// <param name="whereExpression"></param>
    /// <returns></returns>
    Task<List<T>> GetListAsync(Expression<Func<T, bool>>? whereExpression = null);

    /// <summary>
    /// 分页查询(同步)
    /// </summary>
    /// <param name="whereExpression">条件表达式</param>
    /// <param name="intPageIndex">页码（下标0）</param>
    /// <param name="intPageSize">页大小</param>
    /// <param name="intTotalCount">数据总量</param>
    /// <param name="strOrderByFileds">排序字段，如name asc,age desc</param>
    /// <returns>数据列表</returns>
    public List<T> PageList(
        Expression<Func<T, bool>> whereExpression,
        int intPageIndex,
        int intPageSize,
        ref int intTotalCount,
        string strOrderByFileds);

    /// <summary>
    /// 分页查询(异步)
    /// </summary>
    /// <param name="whereExpression">条件表达式</param>
    /// <param name="intPageIndex">页码（下标0）</param>
    /// <param name="intPageSize">页大小</param>
    /// <param name="intTotalCount">数据总量</param>
    /// <param name="strOrderByFileds">排序字段，如name asc,age desc</param>
    /// <returns>数据列表</returns>
    Task<List<T>> PageListAsync(
        Expression<Func<T, bool>> whereExpression,
        int intPageIndex,
        int intPageSize,
        RefAsync<int> intTotalCount,
        string strOrderByFileds);
    #endregion

}
